<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="EduBot用户认证平台，提供安全可靠的登录注册功能，赛博朋克风格界面设计，为教育工作者提供智能教学分析工具的访问入口">
    <meta name="keywords" content="EduBot,教育小助手,课堂行为分析系统登录,教学监测系统注册,郑恩赐技术团队,教育AI平台认证,教育数据可视化,智能教学系统,教育技术专家,深度学习应用,教学评估系统,教育大数据分析,智能课堂管理,异常行为检测">
    <link rel="icon" type="image/png" href="{{ front_end_domain_name }}/static/icons/AiKeTangJiaoXuePingCeXiTong.png">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <title>EduBot - 用户登录注册</title>
    <style>
        body {
            font-family: 'Montserrat', sans-serif;
            background-image: linear-gradient(135deg, #000C24, #2B0036, #0066FF, #000C24);
            background-size: 400% 400%;
            animation: gradientAnimation 15s ease infinite;
            color: #e0e0e0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            overflow: hidden;
            position: relative;
        }
        
        @keyframes gradientAnimation {
            0% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
            100% { background-position: 0% 50%; }
        }
        
        .back-button {
            position: absolute;
            top: 20px;
            left: 20px;
            background: linear-gradient(45deg, #03DAC6, #0066FF);
            border: none;
            color: #121212;
            padding: 15px 30px;
            font-size: 18px;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(3, 218, 198, 0.3);
            font-weight: 700;
            letter-spacing: 1px;
        }
        
        .back-button:hover {
            background: linear-gradient(45deg, #03DAC6, #0099FF);
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(3, 218, 198, 0.5);
        }
        
        button {
            background-color: rgba(3, 218, 198, 0.9);
            border: none;
            color: #121212;
            padding: 14px 30px;
            font-size: 16px;
            border-radius: 50px;
            cursor: pointer;
            margin: 0 15px;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(3, 218, 198, 0.3);
            backdrop-filter: blur(5px);
            font-weight: 600;
        }
        
        button:hover {
            background-color: #03DAC6;
            color: #121212;
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(3, 218, 198, 0.5);
        }
        
        .form {
            background: linear-gradient(145deg, rgba(25, 25, 25, 0.8), rgba(40, 40, 40, 0.8));
            backdrop-filter: blur(10px);
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 
                        0 1px 1px rgba(255, 255, 255, 0.1) inset;
            width: 380px;
            opacity: 0;
            transform: translate(-50%, -50%) scale(0.9);
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            position: absolute;
            top: 50%;
            left: 50%;
            text-align: center;
            pointer-events: none;
            z-index: 1;
            border: 1px solid rgba(187, 134, 252, 0.3);
        }
        
        .form:before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            background: linear-gradient(45deg, #BB86FC, #03DAC6, #0066FF);
            z-index: -1;
            border-radius: 22px;
            opacity: 0.3;
            filter: blur(5px);
        }
        
        .form.show {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
            pointer-events: auto;
            z-index: 2;
        }
        
        .form-header {
            margin-bottom: 30px;
            position: relative;
            text-align: center;
        }
        
        .form-header h2 {
            color: #fff;
            margin: 0 0 10px;
            font-size: 28px;
            font-weight: 700;
            letter-spacing: 1px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.3);
        }
        
        .form-header:after {
            content: '';
            display: block;
            width: 60px;
            height: 3px;
            background: linear-gradient(90deg, #BB86FC, #03DAC6);
            margin: 10px auto 0;
            border-radius: 3px;
        }
        
        label {
            font-size: 16px;
            margin-bottom: 8px;
            display: block;
            text-align: left;
            color: #e0e0e0;
            font-weight: 500;
            letter-spacing: 0.5px;
        }
        
        .input-group {
            margin-bottom: 25px;
            position: relative;
        }
        
        .input-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #BB86FC;
            font-size: 18px;
        }
        
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 15px 15px 15px 45px;
            border: 1px solid rgba(187, 134, 252, 0.4);
            border-radius: 50px;
            background-color: rgba(30, 30, 30, 0.7);
            color: #e0e0e0;
            font-size: 16px;
            transition: all 0.3s ease;
            box-sizing: border-box;
        }
        
        input[type="text"]:focus,
        input[type="password"]:focus {
            border-color: #03DAC6;
            outline: none;
            box-shadow: 0 0 0 3px rgba(3, 218, 198, 0.2);
            background-color: rgba(40, 40, 40, 0.8);
        }
        
        input[type="submit"] {
            background: linear-gradient(45deg, #03DAC6, #0066FF);
            border: none;
            color: #121212;
            padding: 15px 30px;
            font-size: 18px;
            border-radius: 50px;
            cursor: pointer;
            width: 100%;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(3, 218, 198, 0.3);
            font-weight: 700;
            letter-spacing: 1px;
            margin-top: 10px;
        }
        
        input[type="submit"]:hover {
            background: linear-gradient(45deg, #03DAC6, #0099FF);
            transform: translateY(-3px);
            box-shadow: 0 6px 20px rgba(3, 218, 198, 0.5);
        }
        
        button, input[type="submit"] {
            font-weight: 600;
            letter-spacing: 0.5px;
        }
        
        @media (max-width: 480px) {
            .form {
                width: 90%;
                padding: 20px;
            }
            
            .form-header h2 {
                font-size: 24px;
            }
            
            .back-button {
                padding: 10px 20px;
                font-size: 16px;
                top: 15px;
                left: 15px;
                z-index: 10;
            }
            
            input[type="text"],
            input[type="password"] {
                padding: 12px 12px 12px 40px;
                font-size: 14px;
            }
            
            input[type="submit"] {
                padding: 12px 25px;
                font-size: 16px;
            }
            
            .input-icon {
                left: 12px;
                font-size: 16px;
            }
            
            .password-toggle {
                right: 12px;
                padding: 8px;
                margin-right: -4px;
            }
            
            .input-group {
                margin-bottom: 20px;
            }
            
            .password-container {
                margin-bottom: 20px;
            }
            
            .form-footer {
                margin-top: 20px;
                font-size: 12px;
            }
            
            button {
                padding: 12px 25px;
                font-size: 15px;
                margin: 0 10px;
            }
            
            .auto-hide-alert {
                font-size: 14px;
                padding: 12px 20px;
                max-width: 85%;
            }
        }
        
        @media (max-width: 360px) {
            .form {
                padding: 15px;
                margin-top: 0;
            }
            
            .form-header h2 {
                font-size: 22px;
            }
            
            .back-button {
                padding: 8px 15px;
                font-size: 14px;
            }
            
            input[type="submit"] {
                padding: 10px 20px;
                font-size: 15px;
            }
            
            input[type="text"],
            input[type="password"] {
                padding: 10px 10px 10px 35px;
                font-size: 13px;
            }
            
            .input-icon {
                left: 10px;
                font-size: 14px;
            }
            
            .password-toggle {
                font-size: 14px;
            }
            
            .form p {
                font-size: 13px;
            }
            
            .form-footer p {
                font-size: 11px;
            }
            
            .auto-hide-alert {
                font-size: 12px;
                padding: 10px 15px;
                white-space: normal;
                top: 15px;
            }
        }
        
        @media (max-height: 600px) and (orientation: landscape) {
            .form {
                padding: 15px;
                max-height: 85vh;
                overflow-y: auto;
                transform: translate(-50%, -50%) scale(1);
            }
            
            .form.show {
                transform: translate(-50%, -50%) scale(1);
            }
            
            .back-button {
                top: 10px;
                left: 10px;
                padding: 8px 15px;
                font-size: 14px;
            }
            
            .input-group, .password-container {
                margin-bottom: 15px;
            }
        }
        
        a {
            color: #BB86FC;
            text-decoration: none;
            transition: color 0.3s ease;
            font-weight: 500;
        }
        
        a:hover {
            color: #03DAC6;
            text-decoration: underline;
        }
        
        .auto-hide-alert {
            position: fixed;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0, 0, 0, 0.8);
            color: white;
            padding: 15px 25px;
            border-radius: 50px;
            z-index: 9999;
            opacity: 0;
            transition: opacity 0.3s ease;
            backdrop-filter: blur(5px);
            border: 1px solid rgba(187, 134, 252, 0.3);
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
            font-weight: 500;
            max-width: 90%;
            text-align: center;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .auto-hide-alert.show {
            opacity: 1;
        }
        
        .password-container {
            position: relative;
            margin-bottom: 25px;
        }
        
        .password-toggle {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #BB86FC;
            transition: color 0.3s ease;
            z-index: 2;
            padding: 10px;
            margin-right: -10px;
        }
        
        .password-toggle:hover {
            color: #03DAC6;
        }
        
        .form-footer {
            margin-top: 25px;
            text-align: center;
            font-size: 14px;
            color: #999;
        }
        
        #forgotPasswordModal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.8);
            backdrop-filter: blur(8px);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 9999;
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        
        #forgotPasswordModal.show {
            opacity: 1;
            display: flex;
        }
        
        .modal-content {
            background: linear-gradient(145deg, rgba(25, 25, 25, 0.9), rgba(40, 40, 40, 0.9));
            padding: 30px;
            border-radius: 20px;
            width: 90%;
            max-width: 400px;
            text-align: center;
            position: relative;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
            border: 1px solid rgba(187, 134, 252, 0.3);
            transform: scale(0.9);
            transition: transform 0.3s ease;
            animation: modalAppear 0.3s forwards;
        }
        
        @keyframes modalAppear {
            0% { transform: scale(0.9); opacity: 0; }
            100% { transform: scale(1); opacity: 1; }
        }
        
        .modal-content:before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            background: linear-gradient(45deg, #BB86FC, #03DAC6, #0066FF);
            z-index: -1;
            border-radius: 22px;
            opacity: 0.3;
            filter: blur(5px);
        }
        
        .modal-header {
            margin-bottom: 20px;
            position: relative;
        }
        
        .modal-header h3 {
            color: #fff;
            margin: 0 0 10px;
            font-size: 24px;
            font-weight: 700;
        }
        
        .close-modal {
            position: absolute;
            top: -15px;
            right: -15px;
            background: rgba(25, 25, 25, 0.9);
            color: #BB86FC;
            border: 1px solid rgba(187, 134, 252, 0.4);
            width: 30px;
            height: 30px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
        }
        
        .close-modal:hover {
            background: #BB86FC;
            color: #121212;
            transform: rotate(90deg);
        }
        
        .qr-code-container {
            margin: 20px auto;
            max-width: 250px;
        }
        
        .qr-code-container img {
            width: 100%;
            height: auto;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }
        
        .modal-footer {
            margin-top: 20px;
            font-size: 14px;
            color: #e0e0e0;
            line-height: 1.5;
        }
        
        @media (max-width: 480px) {
            .modal-content {
                width: 85%;
                padding: 20px;
            }
            
            .modal-header h3 {
                font-size: 20px;
            }
            
            .qr-code-container {
                max-width: 200px;
            }
            
            .modal-footer {
                font-size: 13px;
            }
        }
    </style>
</head>
<body>
    <h1 style="display: none;">EduBot - 用户登录注册</h1>
    <div id="autoHideAlert" class="auto-hide-alert"></div>
    <button class="back-button" onclick="window.location.href='{{ front_end_domain_name }}/index_page'"><i class="fas fa-arrow-left"></i> 返回首页</button>
    
    <div id="forgotPasswordModal">
        <div class="modal-content">
            <div class="modal-header">
                <h3>重置密码</h3>
                <div class="close-modal" onclick="closeForgotPasswordModal()">
                    <i class="fas fa-times"></i>
                </div>
            </div>
            <div class="qr-code-container">
                <img src="{{ front_end_domain_name }}/static/qr_code/my_wechat_qr_code.jpg" alt="微信二维码">
            </div>
            <div class="modal-footer">
                <p>请扫描上方二维码添加管理员微信</p>
                <p>请备注您的用户名，我们将尽快为您处理密码重置</p>
            </div>
        </div>
    </div>
    
    <form id="loginForm" class="form" action="{{ backend_domain_name }}/login_register/login" method="post">
        <div class="form-header">
            <h2>用户登录</h2>
        </div>
        <div class="input-group">
            <i class="fas fa-user input-icon"></i>
            <input type="text" id="username" name="username" placeholder="请输入用户名">
        </div>
        <div class="password-container">
            <i class="fas fa-lock input-icon"></i>
            <input type="password" id="password" name="password" placeholder="请输入密码">
            <i class="fas fa-eye password-toggle" id="loginEye" onclick="togglePasswordVisibility('password', 'loginEye')"></i>
        </div>
        <input type="submit" value="登录">
        <div style="display: flex; justify-content: space-between; margin-top: 20px; font-size: 15px;">
            <a href="#" onclick="showForgotPasswordModal(); return false"><i class="fas fa-key"></i> 忘记密码？</a>
            <a href="#" onclick="showRegisterForm(); return false">没有账号？去注册</a>
        </div>
        <div class="form-footer">
            <p><i class="fas fa-info-circle"></i> 登录成功后24小时内保持有效（主动退出除外）</p>
        </div>
    </form>
    <form id="registerForm" class="form" action="{{ backend_domain_name }}/login_register/register" method="post">
        <div class="form-header">
            <h2>用户注册</h2>
        </div>
        <div class="input-group">
            <i class="fas fa-user input-icon"></i>
            <input type="text" id="registerUsername" name="username" placeholder="请输入用户名（不超过16个字符）">
        </div>
        <div class="password-container">
            <i class="fas fa-lock input-icon"></i>
            <input type="password" id="registerPassword" name="password" placeholder="请输入密码（不超过32个字符）">
            <i class="fas fa-eye password-toggle" id="registerEye" onclick="togglePasswordVisibility('registerPassword', 'registerEye')"></i>
        </div>
        <div class="password-container">
            <i class="fas fa-check-circle input-icon"></i>
            <input type="password" id="confirmPassword" name="confirmPassword" placeholder="请再次输入密码">
            <i class="fas fa-eye password-toggle" id="confirmEye" onclick="togglePasswordVisibility('confirmPassword', 'confirmEye')"></i>
        </div>
        <input type="submit" value="注册">
        <p style="text-align: right; margin-top: 20px; font-size: 15px;">
            已有账号？<a href="#" onclick="showLoginForm(); return false">去登录</a>
        </p>
    </form>
    <script>
        const backendDomainName = '{{ backend_domain_name }}';
        const frontEndDomain = '{{ front_end_domain_name }}';

        function showAutoHideMessage(message) {
            const alertDiv = document.getElementById('autoHideAlert');
            alertDiv.textContent = message;
            alertDiv.classList.add('show');
            
            setTimeout(() => {
                alertDiv.classList.remove('show');
            }, 3000);
        }

        window.onload = function() {
            const token = localStorage.getItem('token');
            if (token) {
                checkToken(token);
            } else {
                showLoginForm();
            }
        };

        function checkToken(token) {
            const formData = new FormData();
            formData.append('token', token);
            
            fetch(backendDomainName + '/login_register/check_token', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.TF === 'T') {
                    window.location.href = frontEndDomain + '/navigation_page';
                } else {
                    localStorage.removeItem('token');
                    showLoginForm();
                }
            })
            .catch(error => {
                showAutoHideMessage('验证会话失败，请重新登录');
                localStorage.removeItem('token');
                showLoginForm();
            });
        }

        const loginForm = document.getElementById('loginForm');
        const registerForm = document.getElementById('registerForm');

        function showLoginForm() {
            registerForm.classList.remove('show');
            setTimeout(() => {
                registerForm.style.display = 'none';
                loginForm.style.display = 'block';
                setTimeout(() => loginForm.classList.add('show'), 10);
            }, 300);
        }

        function showRegisterForm() {
            loginForm.classList.remove('show');
            setTimeout(() => {
                loginForm.style.display = 'none';
                registerForm.style.display = 'block';
                setTimeout(() => registerForm.classList.add('show'), 10);
            }, 300);
        }

        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            showAutoHideMessage('登录请求发送中，请稍候...');
            
            const loginButton = this.querySelector('input[type="submit"]');
            const originalText = loginButton.value;
            loginButton.value = '登录中...';
            loginButton.disabled = true;
            
            fetch(this.action, {
                method: 'POST',
                body: new FormData(this)
            })
            .then(response => response.json())
            .then(data => {
                if (data.token) {
                    showAutoHideMessage('登录成功，正在跳转...');
                    localStorage.setItem('token', data.token);
                    
                    setTimeout(() => {
                        window.location.href = frontEndDomain + '/navigation_page';
                    }, 1000);
                } else if (data.error) {
                    showAutoHideMessage(data.error);
                }
            })
            .catch(error => {
                showAutoHideMessage('登录失败，请检查网络连接');
            })
            .finally(() => {
                loginButton.value = originalText;
                loginButton.disabled = false;
            });
        });

        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const username = document.getElementById('registerUsername').value;
            const pwd = document.getElementById('registerPassword').value;
            const confirm = document.getElementById('confirmPassword').value;
            
            if (username.length >= 16) {
                showAutoHideMessage('用户名长度不能超过16个字符');
                return;
            }
            if (pwd.length >= 32) {
                showAutoHideMessage('密码长度不能超过32个字符');
                return;
            }
            if (pwd !== confirm) {
                showAutoHideMessage('两次输入的密码不一致！');
                return;
            }
            
            showAutoHideMessage('注册请求发送中，请稍候...');
            
            const registerButton = this.querySelector('input[type="submit"]');
            const originalText = registerButton.value;
            registerButton.value = '注册中...';
            registerButton.disabled = true;
            
            const formData = new FormData();
            formData.append('username', username);
            formData.append('password', pwd);
            
            fetch(this.action, {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.code === 1) {
                    showAutoHideMessage(data.message);
                    setTimeout(() => {
                        showLoginForm();
                    }, 1500);
                } else {
                    showAutoHideMessage(data.message);
                }
            })
            .catch(error => {
                showAutoHideMessage('注册失败，请检查网络连接');
            })
            .finally(() => {
                registerButton.value = originalText;
                registerButton.disabled = false;
            });
        });

        function togglePasswordVisibility(inputId, eyeId) {
            const input = document.getElementById(inputId);
            const eye = document.getElementById(eyeId);
            if (input.type === 'password') {
                input.type = 'text';
                eye.classList.remove('fa-eye');
                eye.classList.add('fa-eye-slash');
            } else {
                input.type = 'password';
                eye.classList.remove('fa-eye-slash');
                eye.classList.add('fa-eye');
            }
        }
        
        function showForgotPasswordModal() {
            const modal = document.getElementById('forgotPasswordModal');
            modal.style.display = 'flex';
            setTimeout(() => {
                modal.classList.add('show');
            }, 10);
        }
        
        function closeForgotPasswordModal() {
            const modal = document.getElementById('forgotPasswordModal');
            modal.classList.remove('show');
            setTimeout(() => {
                modal.style.display = 'none';
            }, 300);
        }
    </script>
</body>
</html>